﻿using System.Windows;
using JY.Wpf.Core.CaseForCaliburn;
using JY.Wpf.TestForMetro.ViewModels;
using Microsoft.Extensions.DependencyInjection;
using SD.IOC.Core.Mediators;
using SD.IOC.Extension.NetFx;

namespace JY.Wpf.TestForMetro.Commons
{
    /// <summary>
    /// 引导程序
    /// </summary>
    public class Bootstrapper : JYBootstrapperBase
    {
        #region # 构造器
        /// <summary>
        /// 构造器
        /// </summary>
        public Bootstrapper() : base()
        {
        }
        #endregion

        #region # 应用程序启动事件——void OnStartup(object sender, StartupEventArgs e)
        /// <summary>
        /// 应用程序启动事件
        /// </summary>
        protected override void OnStartup(object sender, StartupEventArgs e)
        {
            //var splashScreen = new SplashScreen("Images/StartUp.jpg");
            //splashScreen.Show(true);
            this.DisplayRootViewFor<ShellViewModel>();
            //ResolveMediator.Resolve<IEventAggregator>().PublishOnUIThread(new ShowChildWindowEvent<ChildWindowViewModelBase>(new LoginViewModel("JY.Wpf.TestForMetro", "", true)));
        }
        #endregion

        #region # 自动登录——virtual void AutoLogin()
        /// <summary>
        /// 自动登录
        /// </summary>
        /// <returns></returns>
        public override void AutoLogin()
        {
            //ResolveMediator.Resolve<IEventAggregator>().PublishOnUIThread(new LoginEvent(SystemConfig.UserName, SystemConfig.Password));
        }
        #endregion

        #region # 异常处理
        #endregion

        #region 配置应用程序 —— override void Configure()
        /// <summary>
        /// 配置应用程序
        /// </summary>
        protected override void Configure()
        {
            //初始化依赖注入容器
            if (!ResolveMediator.ContainerBuilt)
            {
                IServiceCollection serviceCollection = ResolveMediator.GetServiceCollection();
                serviceCollection.RegisterConfigs();
                ResolveMediator.Build();
            }
        }
        #endregion
    }
}
